package com.ykdl.member.kid.prefs;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.Editable;
/**
 * 记录 登录状态，我的一些个人信息，获取动态的时间 
 * 
 * @param result
 */
public class IAskMyActionPre {
	private static final String LABEL = "iskmyaction";

	public static void setMyActionTime(Context context, String time) {	
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("myactiontime", time);		
		editor.commit();	
	}

	public static String getMyActionTime(Context context) {
		//2012-09-20 11:11:11 ,程序上线的时间,从服务器获取新新数据的起始时间
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("myactiontime", "2012-09-20 11:11:11");
	}
	
	public static void setTotalLikeNum(Context context, int like) {	
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("like", Integer.parseInt(getTotalLike(context))+like+"");		
		editor.commit();	
	}

	public static String getTotalLike(Context context) {
		//2012-09-20 11:11:11 ,程序上线的时间
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("like", "0");
	}
	
	public static void setMymsgNum(Context context, int like) {	
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putInt("mymsg", Integer.parseInt(getTotalLike(context))+like);		
		editor.commit();	
	}

	public static int getMymsgNum(Context context) {
		//2012-09-20 11:11:11 ,程序上线的时间
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getInt("mymsg", 0);
	}
	
	public static void setFetchGreenTime(Context context, long time) {	
		//上次 刷新绿色通道
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putLong("greentime", time);		
		editor.commit();	
	}

	public static long getFetchGreenTime(Context context) {
		////上次 刷新绿色通道
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getLong("greentime", 0);
	}
	
	public static void setFetchMyActionTime(Context context, long time) {	
		//上次刷新 动态的时间
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putLong("fetchactiontime", time);		
		editor.commit();	
	}

	public static long getFetchMyActionTime(Context context) {
		//上次刷新 动态的时间
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getLong("fetchactiontime", 0);
	}
	
	
	public static void seLonOn(Context context, String logon) {	
		//上次刷新 动态的时间
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("iasklogon", logon);		
		editor.commit();	
	}

	public static String getLogOn(Context context) {
		//上次刷新 动态的时间
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("iasklogon", "");
	}
	
	public static void setDoctimeContent(Context context, String content) {	
		//获取到的抽号的内容
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("doccontent", content);		
		editor.commit();	
	}

	public static String getDoctimeContent(Context context) {
		//获取到的抽号的内容
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("doccontent", "");
	}
	
	public static void setDoctimeTime(Context context, long time) {	
		//上次获取抽号的时间
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putLong("doctime", time);		
		editor.commit();	
	}

	public static long getDoctimeTime(Context context) {
		//上次获取抽号的时间
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getLong("doctime", 0);
	}
	
	public static void setTipMessageID(Context context, String id) {	
		//上次获取抽号的时间
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("msg"+id, id);		
		editor.commit();	
	}

	public static String getTipMessageID(Context context,String id) {
		//上次获取抽号的时间
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("msg"+id, "");
	}
	
	public static void setJoinLogonLuck(Context context,String userid,String evetnid ) {	
		//成功参加注册抽奖
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("joinevent"+userid, evetnid);		
		editor.commit();	
	}

	public static String getJoinLogonLuck(Context context,String userid) {
		//成功参加注册抽奖
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("joinevent"+userid, "");
	}
	
	public static void setLogonEventOut(Context context, String eventid) {	
		//上次获取抽号的时间
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("event"+eventid, eventid);		
		editor.commit();	
	}

	public static String getLogonEventOut(Context context,String eventid) {
		//上次获取抽号的时间
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("event"+eventid, "");
	}
	
	public static void setLucyEventID(Context context, String eventid,String code,String content) {	
		//中奖信息
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("lucy"+eventid, eventid+"#"+code+"#"+content);			
		editor.commit();	
	}

	public static String getLucyEventID(Context context,String eventid) {
		//中奖信息	
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("lucy"+eventid, "");
	}
	
	
	public static void setAskDocTime(Context context, String time) {	
		//抽号问医生，已经问过的时间段
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("docask"+time, "111");			
		editor.commit();	
	}

	public static String getAskDocTime(Context context,String time) {
		//抽号问医生，已经问过的时间段
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("docask"+time, "");
	}
	
	public static void setAnserRenumber(Context context, String answesrid,String number) {	
		// 我的动态,我的答案被回复的数
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("reanswernum"+answesrid, number);			
		editor.commit();	
	}

	public static String getAnserRenumber(Context context,String answerid) {
		// 我的动态,我的答案被回复的数
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("reanswernum"+answerid, "0");
	}
	
	
	public static void setAnswerLilk(Context context, String answerid,String likenum) {	
		// 我的动态,我的答案被喜欢的数
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("answerlike"+answerid,likenum);			
		editor.commit();	
	}

	public static String getAnswerLilk(Context context,String answerid) {
		// 我的动态,我的答案被喜欢的数
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("answerlike"+answerid, "0");
	}
	
	public static void setAnswerNumber(Context context, String askid,String num) {	
		// 我的动态,我的问题的答案数
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("ask"+askid,num);			
		editor.commit();	
	}

	public static String getAnswerNumber(Context context,String askid) {
		// 我的动态,我的问题的答案数
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("ask"+askid, "0");
	}
	
	
	public static void setNotFisrFetchAction(Context context) {	
		// 我的动态,是否是第一次获取
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("first","not");			
		editor.commit();	
	}
	
	public static void setNotFisrFetchAction(Context context,String value) {	
		// 我的动态,是否是第一次获取
		Editor editor = context.getSharedPreferences(LABEL,
				Context.MODE_PRIVATE).edit();
		editor.putString("first",value);			
		editor.commit();	
	}

	public static String getNotFisrFetchAction(Context context) {
		// 我的动态,是否是第一次获取
		return context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).getString("first", "");
	}
	
	public static void clearAllData(Context context) {
		// 我的动态,是否是第一次获取
		Editor er= context.getSharedPreferences(LABEL, Context.MODE_PRIVATE).edit();
		er.clear();
		er.commit();
	}
	
	public static void setTodaySign(Context context){
		SharedPreferences shar = context.getSharedPreferences(LABEL, Context.MODE_PRIVATE);
		Editor editor = shar.edit();
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
		editor.putString("sign_date", format.format(new Date(System.currentTimeMillis())));
		editor.commit();
	}
	
	public static boolean haveSignIfToday(Context context){
		boolean todaySign = false;
		SharedPreferences shar = context.getSharedPreferences(LABEL, Context.MODE_PRIVATE);
		String today = shar.getString("sign_date", "");
		if (today.equals("")) {
			todaySign = false;
		} else {
			SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
			String cruDate = format.format(new Date(System.currentTimeMillis()));
			if (cruDate.equals(today)) {
				todaySign = true;
			} else {
				todaySign = false;
			}
		}
		return todaySign;
	}
	
	
}
